package com.dbz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbz.entity.Business;
import com.dbz.entity.Supplier;
import com.dbz.service.BusinessService;
import com.dbz.service.SupplierService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/supplier/")
@RestController
public class SupplierController {
    @Resource
    private SupplierService supplierService;

    /**
     * 多条件分页查询
     * @param sname
     * @param sphone
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("selectSupplier")
    public Map pageList(String sname,String sphone,Integer page,Integer rows){
        Map<String,Object> map=new HashMap<>();
        QueryWrapper<Supplier> queryWrapper=new QueryWrapper<Supplier>();
        queryWrapper.like(sname!=""&&sname!=null,"sname",sname);
        queryWrapper.eq(sphone!=""&&sphone!=null,"sphone",sphone);
        IPage<Supplier> pages=new Page<Supplier>(page,rows);
        map.put("rows", supplierService.selectPage(pages,queryWrapper).getRecords());
        map.put("total",supplierService.selectPage(pages,queryWrapper).getTotal());
        return  map;
    }

    /**
     * 添加信息
     * @param sname
     * @param sphone
     * @return
     */
    @RequestMapping("insertSupplier")
    public int insertSupplier(String sname,String saccount,String sphone){

        return supplierService.insertSupplier(sname, saccount, sphone);
    }

    /**
     * 修改信息
     * @param sname
     * @param sphone
     * @return
     */
    @RequestMapping("updateSupplier")
    public int updateSupplier(String supplierid,String sname,String saccount,String sphone){
        return supplierService.updateSupplier(supplierid,sname,saccount,sphone);
    }
    /**
     * 删除信息
     * @param supplierid
     * @return
     */
    @RequestMapping("deleteSupplier")
    public int deleteSupplier(String supplierid){
        return supplierService.delecteSupplier(supplierid);
    }
}
